#include "mainwindow.h"

#include "cardscene.h"
#include "cardpoolviewobject.h"


#include <QDebug>
#include <QPushButton>
#include <QApplication>
#include <QDesktopWidget>

MainWindow::MainWindow(QWidget *parent) :
    QWidget(parent)
{

    QVBoxLayout *layout = new QVBoxLayout();

    CardScene *scene;
    scene = new CardScene();
    scene->setSceneRect(QApplication::desktop()->rect().adjusted(0, 0, -300, -450));

    scene->setItemIndexMethod(QGraphicsScene::NoIndex);

    // FOR TEST
    int leftPadding = scene->width();
    int bottomPadding = scene->height();
    CardViewObject *card = new CardViewObject();
    card->setPos(leftPadding - card->cardRect.width() - 10 , bottomPadding);
    card->setZValue(5);
    scene->addItem(card);

    CardPoolViewObject *pool = new CardPoolViewObject();
    pool->setPos(leftPadding, bottomPadding);
    scene->addItem(pool);
    // \FOR TEST


    QGraphicsView *view;
    view = new QGraphicsView(scene);

    view->setRenderHint(QPainter::Antialiasing);
    view->setBackgroundBrush(QPixmap(":/paperbg.jpg"));


    view->setCacheMode(QGraphicsView::CacheBackground);
    view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);

    setWindowTitle("MTG");

    layout->addWidget(view);
    setLayout(layout);

    connect(scene, SIGNAL(selectionChanged()), this, SLOT(SelectionChangedSlot()));

    m_GameController = new GameControllerMTG(scene);

    m_GameController->addPool(new CardPool("./mtg_deck_default.xml"));
    m_GameController->addPool(new CardPool("./mtg_deck_default.xml"));
    m_GameController->run();


}

MainWindow::~MainWindow()
{

}

void MainWindow::changeEvent(QEvent *)
{

}

void MainWindow::SelectionChangedSlot()
{

}
